package com.exp.gxl.controller;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import org.apache.ibatis.session.SqlSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.exp.gxl.bean.IUser;

@RestController
@RequestMapping(value = "/index")
public class IndexController {
	
	@Value("${roncoo.secret}")
	private String randomVal;
	
	@Autowired
	SqlSession session;
	
	@RequestMapping()
	public String index(){
		return "Hello World";
	}
	
	@RequestMapping(value = "/get")
	public Map<String,String> get(@RequestParam(required = false) String name){
		Map<String,String> map = new HashMap<>();
		map.put("val", "Hello World");
		
		return map;
	}
	
	@RequestMapping(value = "/getUser/{id}/{name}")
	public IUser getUser(@PathVariable(required = false) Integer id,@PathVariable(required = false) String name){
		
		System.out.println(session.hashCode());
		
		IUser iUser = new IUser();
		iUser.setId(id);
		iUser.setUsername(this.randomVal);
		iUser.setRegDate(new Date());
		return iUser;
	}
	

}
